package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.UniversityMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.RoleExample;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.University;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.UniversityExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UniversityServiceImpl implements IUniversityService{
    @Autowired
    UniversityMapper universityMapper;

    @Override
    public int insertUniversity(University university) {
        return universityMapper.insert(university);
    }

    @Override
    public List<University> queryAllUniversity() {
        List<University> universities = universityMapper.selectAll();
        return universities;
    }

    @Override
    public University queryUniversityById(Integer id) {
        return universityMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteUniversityById(Integer id) {
        return universityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateUniversityById(University university) {
        return universityMapper.updateByPrimaryKey(university);
    }

    @Override
    public int queryUniversityCount() {
        UniversityExample universityExample = new UniversityExample();
        UniversityExample.Criteria criteria = universityExample.createCriteria();
        criteria.getAllCriteria();
        return (int) universityMapper.countByExample(universityExample);
    }

    @Override
    public List<University> queryUniversityByPage(int pageNow, int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<University> universities = this.queryAllUniversity();
        PageInfo<University> universityPageInfo = new PageInfo<>(universities);
        return universityPageInfo.getList();
    }

}
